package com.artqiyi.dollmachine.views.widget;

import android.content.Context;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import timber.log.Timber;

/**
 * author: PengCheng
 * time: 2018/1/31 0031
 * desc:
 */

public class MyLayoutManager extends LinearLayoutManager {

    private int height;
    public MyLayoutManager(Context context) {
        super(context);
    }


    @Override
    public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) {
//        Timber.d("MyLayoutManager_count:" + getChildCount());
//        final int width = RecyclerView.LayoutManager.chooseSize(widthSpec,
//                getPaddingLeft() + getPaddingRight(),
//                ViewCompat.getMinimumWidth(mList));
//        final int height = RecyclerView.LayoutManager.chooseSize(heightSpec,
//                getPaddingTop() + getPaddingBottom(),
//                ViewCompat.getMinimumHeight(mList));
//        setMeasuredDimension(width, height * mTelList.size());
//        if (getChildCount() > 4) {
//            View firstChildView = recycler.getViewForPosition(0);
//            measureChild(firstChildView, widthSpec, heightSpec);
//            setMeasuredDimension(View.MeasureSpec.getSize(widthSpec), firstChildView.getMeasuredHeight() * 4 + 5);
//            height = firstChildView.getMeasuredHeight() * 4 + 5;
//        } else {
//            super.onMeasure(recycler, state, widthSpec, heightSpec);
//        }

//        View view = recycler.getViewForPosition(0);
//        if(view != null){
//            measureChild(view, widthSpec, heightSpec);
//            int measuredWidth = View.MeasureSpec.getSize(widthSpec);
//            int measuredHeight = view.getMeasuredHeight();
//            setMeasuredDimension(measuredWidth, measuredHeight *4);
//        }
    }

    public int getHeight() {
        return height;
    }
}
